<?php
namespace app\np\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\Db;
use think\Config;
class Table extends Command
{
    protected function configure()
    {
        $this->setName('table')->setDescription('Here is the remark ');
        $this->addArgument('table', Argument::REQUIRED); //必传参数
    }
    protected function execute(Input $input, Output $output)
    {
        $args = $input->getArguments();
        $database =Config::get('database.database');
        $prefix =Config::get('database.prefix');
         if(isset($args['table']))   {
             $n_table = $prefix.$args['table'];
             $rs = Db::query("SHOW TABLES LIKE '".$n_table."' ");
             if(!empty($rs)){
                 $output->writeln("TestCommand:this table {$n_table} is exist");
                    return false;
             }
         }

$sql = <<<sql
CREATE TABLE `$n_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `displayorder` int(11) DEFAULT '0',
  `created_at` int(12) DEFAULT NULL,
  `update_at` int(12) DEFAULT NULL,
  `isdelete` smallint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
sql;

       $res= Db::execute($sql);
        $output->writeln("TestCommand:create table {$n_table} sucess");
    }
}